<template>
	<view class="index">
		<view class="uni-card">
			<view class="uni-list">
				<view class="uni-list-cell-divider">
					名称：
				</view>
				<view class="uni-list-cell con-list">
					{{data.type_name}}
				</view>
				
				<view class="uni-list-cell-divider" v-if="data.remark">
					备注：
				</view>
				<view class="uni-list-cell con-list" v-if="data.remark">
					<rich-text :nodes="data.remark"></rich-text>
				</view>
				
				<view class="uni-list-cell con-list" hover-class="uni-list-cell-hover" v-if="data.file">
					<view class="uni-list-cell-navigate uni-navigate-right" @click="openFile()">
						<label>点击查看采样标准</label>
					</view> 
				</view>
				
			</view>
		</view>
		
	</view>
</template>

<script>
	
	import net from '../../net.js';
	import service from '../../service.js';
	import utils from '../../common/utils.js';
	import uniIcons from '@/components/uni-icons/uni-icons.vue';
	
	export default {
		components: {
			uniIcons
		},
		data() {
			return {
				data: {},
				standardId: '',
				filePath: ''
			}
		},
		onLoad(res) {
			this.data = {};
			this.standardId = res.standardId;
			this.filePath = '';
			this.getStandard();
		},
		methods: {
			getStandard() {
				net.netGet('/module/api/main/showSampleStandard/'+encodeURIComponent(this.standardId), {}, (res)=>{
					//console.log(res);
					this.data = res || {};
					if(this.data.remark) {
						this.data.remark = this.data.remark.replace(/neue\';"=""/g, '');
					}
				}, ()=>{
					uni.showToast({icon: 'none', title: '无法获取采样标准'});
				}, (res)=> {
					//console.log(JSON.stringify(res));
					
				});	
			},
			openFile() {
				if(this.filePath) {
					uni.openDocument({
					  filePath: this.filePath,
					  success: (res)=> {
						console.log('打开文档成功');
					  },
					  fail:() =>{
					  	uni.showToast({icon: 'none',title: '无法打开文件'});
					  }
					});
				}else {
					uni.downloadFile({
					  url: this.data.file,
					  //header: { Token: service.getToken() },
					  success: (res)=> {
						this.filePath = res.tempFilePath;
						uni.openDocument({
						  filePath: this.filePath,
						  success: (res)=> {
							console.log('打开文档成功');
						  },
						  fail: ()=> {
						  	uni.showToast({icon: 'none',title: '无法打开文件'});
						  }
						});
					  },
					  fail: ()=> {
					  	uni.showToast({icon: 'none',title: '无法打开文件'});
					  }
					});
				}
			}
		},
	}
</script>

<style>
	.index{
		width: 100%;
	}
	.uni-card {
		margin: 50upx 0 60upx 0;
	}
	
	.uni-list-cell:after {
		left: 0;
	}
	
	.uni-list-cell {
		padding: 0 20upx;
		min-height: 90upx;
		color: #666;
	}
	
	.uni-list-cell.con-list {
		flex-wrap: wrap;
	}
	
	.uni-list-cell.con-list text {
		flex: 0 0 100%;
		font-size: 32upx;
	}
	
	.uni-list-cell-divider ~ .uni-list-cell {
		padding-left: 50upx;
		min-height: 70upx;
	}
	
	.uni-list-cell.no-left {
		padding-left: 20upx;
	}
	
</style>
